package io.shallwe._admin.line;

import com.jfinal.plugin.activerecord.Record;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.time.LocalDate;

/**
 * @Description: java端打印模板，当前暂时不用
 * @author: gkw
 * @description: io.shallwe._admin.line
 * @date:2019/9/9
 **/
public class TurnoverVehiclePrintModel implements Printable {

    private String materialCount;
    private String traceCode;
    private String materialCode;
    private String materialName;
    private String barCode;

    public TurnoverVehiclePrintModel(String materialCode,String materialName,String materialCount, String traceCode, String barCode){
        this.barCode = barCode;
        this.materialCode = materialCode;
        this.materialCount = materialCount;
        this.materialName = materialName;
        this.traceCode = traceCode;
    }

    @Override
    public int print(Graphics graphics, PageFormat pageFormat, int i) throws PrinterException {

        String qrCodeCount = "F"+traceCode+"#"+materialCode+"#"+barCode;
        String countCodeCount = "Q"+materialCount;
        //ST条形码，注意最后带空格
        String stCodeCount = "ST ";
        String lastCodeCount = "S0"+barCode;
        //获取可打印区域的左上方起始坐标X轴的位置
        int x = (int) pageFormat.getImageableX();
        //获取可打印区域的左上方起始坐标Y轴的位置
        int y = (int) pageFormat.getImageableY();

        int baseWidth=45;
        int baseHeight=10;
        graphics.drawRect(baseWidth,baseHeight,530,340);
        //画横线
        graphics.drawLine(baseWidth,baseHeight+80,baseWidth+530,baseHeight+80);
        graphics.drawLine(baseWidth,baseHeight+80+64,baseWidth+530,baseHeight+80+64);
        graphics.drawLine(baseWidth,baseHeight+80+64+32,baseWidth+530,baseHeight+80+64+32);
        graphics.drawLine(baseWidth,baseHeight+80+64+32+48,baseWidth+530,baseHeight+80+64+32+48);

        graphics.drawLine(baseWidth+270+125,baseHeight+80+64+32+48+29,baseWidth+530,baseHeight+80+64+32+48+29);
        graphics.drawLine(baseWidth+275,baseHeight+80+64+32+48+58,baseWidth+530,baseHeight+80+64+32+48+58);
        //画竖线
        graphics.drawLine(baseWidth+275,baseHeight+80,baseWidth+275,baseHeight+340);
        graphics.drawLine(baseWidth+395,baseHeight+80+64,baseWidth+395,baseHeight+80+64+32);
        graphics.drawLine(baseWidth+395,baseHeight+80+64+32+48,baseWidth+395,baseHeight+80+64+32+48+58);
        graphics.drawLine(baseWidth+440,baseHeight,baseWidth+440,baseHeight+80);

        graphics.setFont(new Font("Dialog",Font.PLAIN,7));
        graphics.drawString("物料编码:",baseWidth+3,baseHeight+10);
        graphics.drawString("数量:",baseWidth+3,baseHeight+10+80);
        graphics.drawString("SUT:",baseWidth+3+275,baseHeight+10+80);
        graphics.drawString("送达方:",baseWidth+3,baseHeight+10+80+64);
        graphics.drawString("需求日期:",baseWidth+3+275,baseHeight+10+80+64);
        graphics.drawString("工程变更:",baseWidth+3+275+125,baseHeight+10+80+64);
        graphics.drawString("库存地点:",baseWidth+3,baseHeight+10+80+64+32);
        graphics.drawString("包装:",baseWidth+3+275,baseHeight+10+80+64+32);
        graphics.drawString("条码号:",baseWidth+3,baseHeight+10+80+64+32+48);
        graphics.drawString("上下架策略标识:",baseWidth+3+270+125,baseHeight+10+80+64+32+48);
        graphics.drawString("仓位:",baseWidth+3+270+125,baseHeight+10+80+64+32+48+29);
        graphics.drawString("跟踪号:",baseWidth+3+275,baseHeight+10+80+64+32+48+58);
        //  天纳克图片
        Image logoImage=Toolkit.getDefaultToolkit().getImage(Panel.class.getResource("/logo.png"));
        graphics.drawImage(logoImage,baseWidth+275+3,baseHeight+10+80+64+32+48,117,35,null);

        graphics.setFont(new Font("Dialog",Font.PLAIN,16));
        graphics.drawString("PC",baseWidth+245,baseHeight+15+80);
        graphics.drawString("BEM1",baseWidth+3,baseHeight+10+80+64+32+20);

        graphics.setFont(new Font("Dialog",Font.BOLD,27));
        graphics.drawString("ST",baseWidth+10+275,baseHeight+10+80+30);
        graphics.drawString(materialCode,baseWidth+3,baseHeight+46);
        graphics.drawString(materialCount,baseWidth+80,baseHeight+25+80);
        graphics.drawString(barCode,baseWidth+6,baseHeight+80+64+32+48+40);
        graphics.drawString(traceCode,baseWidth+3+275,baseHeight+40+80+64+32+48+58);

        graphics.setFont(new Font("Dialog",Font.BOLD,20));
        LocalDate localDate = LocalDate.now();
        String localDateStr=localDate.getYear()+"."+localDate.getMonthValue()+"."+localDate.getDayOfMonth();
        graphics.drawString(localDateStr,baseWidth+3+275,baseHeight+30+80+64);

        graphics.setFont(new Font("Dialog",Font.PLAIN,20));
        graphics.drawString(materialName,baseWidth+3,baseHeight+70);

        QRCodeKit qrCodeKit = new QRCodeKit();
        //画二维码
        BufferedImage qrcode = qrCodeKit.createQRCode(qrCodeCount,70,70,0);
        graphics.drawImage(qrcode,baseWidth+440+10,baseHeight+5,null);
        //画一维码
        BufferedImage countCode = qrCodeKit.createBarCode(countCodeCount,250,25);
        graphics.drawImage(countCode,baseWidth+1,baseHeight+80+30,null);

        BufferedImage stCode = qrCodeKit.createBarCode(stCodeCount,200,30);
        graphics.drawImage(stCode,baseWidth+250+75,baseHeight+80+20,null);

        BufferedImage lastCode = qrCodeKit.createBarCode(lastCodeCount,270,35);
        graphics.drawImage(lastCode,baseWidth+1,baseHeight+80+64+32+48+70,null);

        //打印操作
        return Printable.PAGE_EXISTS;
    }
}
